package com.example.sunming.java8fenye;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * @author: sunming
 * @description
 * @date: 2021/5/20 14:05
 */
public class TestSkip {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(i);
        }

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入当前页数：");
        int page = scanner.nextInt();
        System.out.println("请输入每页显示个数：");
        int limit = scanner.nextInt();
        System.out.println("第" + page + "页数据:" + getPageResult(list, page, limit));
    }


    /**
     * 分页方法
     *
     * @return
     */
    public static List<Integer> getPageResult(List<Integer> list, int page, int size) {
        return list.stream().skip((page - 1) * size)
                .limit(size).collect(Collectors.toList());
    }
}
